﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DVSProject.Lib;
using DVSProject.Models;

namespace DVSProject.Controllers
{
    public class AccessController : Controller
    {
        //
        // GET: /VisitProcess/

        public ActionResult Index()
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            AccessRepo accessRepo = new AccessRepo();
            DVSProject.Models.EmployeeModels employee = (DVSProject.Models.EmployeeModels)Session["Employee"];
            IEnumerable<AccessModels> access;// = new  IEnumerable<AccessModels>;
            if (employee.dept_id == 1)
            {
                access = accessRepo.GetAccess((string)Session["User"]);
            }
            else
            {
                access = accessRepo.GetAccess();
            }




            return View(access);
        }

        //
        // GET: /VisitProcess/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /VisitProcess/Create

        public ActionResult Create()
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            LocationSetRepo customerRepo = new LocationSetRepo();
            IEnumerable<LocationSetModels> locationSets = customerRepo.GetLocationSet();

            string selectedLocationCode = "";
            IEnumerable<SelectListItem> selectlist = from s in locationSets
                                                     select new SelectListItem
                                                     {
                                                         Selected = (s.LocationSetCode == selectedLocationCode),
                                                         Text = s.LocationSetCode + '-' + s.LocSetNameTh,
                                                         Value = s.LocationSetCode.ToString()
                                                     };

            var access = new AccessModels { locationSets = locationSets, locationSetSelect = selectlist };
            return View(access);
        }

        //
        // POST: /VisitProcess/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                // TODO: Add insert logic here
                AccessModels access = new AccessModels();
                access.LocationSetCode = collection["LocationSetCode"];
                access.CreateBy = (string)Session["User"];
                AccessRepo accessRepo = new AccessRepo();
                bool result = accessRepo.Create(access);

                if (result)
                {
                    return RedirectToAction("SelectDateTime");
                }
                return RedirectToAction("Create");
            }
            catch
            {
                return View();
            }
        }


        public ActionResult SelectDateTime()
        {


            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            AccessRepo accessRepo = new AccessRepo();
            AccessModels accessModel = accessRepo.GetVisitTemp((string)Session["User"]);

            LocationMachineSetRepo locationsetRepo = new LocationMachineSetRepo();
            IEnumerable<LocationMachineSetModels> locationMachineSets = locationsetRepo.GetLocationMachineSetByLocationSetCode(accessModel.LocationSetCode);

            string selectedSerialNo = "";
            IEnumerable<SelectListItem> selectlist = from s in locationMachineSets
                                                     select new SelectListItem
                                                     {
                                                         Selected = (s.SerialNo == selectedSerialNo),
                                                         Text = s.Machine_Name,
                                                         Value = s.SerialNo.ToString()
                                                     };




            var access = new AccessModels
            {
                locationMachineSets = locationMachineSets,
                locationMachineSetSelect = selectlist
                ,
                LocationSetCode = accessModel.LocationSetCode
                ,
                LocationSetCodeFullName = accessModel.LocationSetCodeFullName
                ,
                DateTimeIn = accessModel.DateTimeIn

            };

            return View(access);
        }

        [HttpPost]
        public ActionResult SelectDatetime(FormCollection collecton)
        {
            try
            {
                if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                // TODO: Add update logic here
                AccessModels access = new AccessModels();
                access.SerialNo = collecton["locationMachineSets"];
                access.WorkType = collecton["WorkType"];
                access.CreateBy = (string)Session["User"];

                if (access.SerialNo == "")
                {
                    TempData["errormessage"] = "ยังไม่ได้เลือกเครื่อง";
                }
                else
                {
                    AccessRepo accessRepo = new AccessRepo();
                    bool result = accessRepo.UpdateMachine(access);

                    if (result)
                    {
                        return RedirectToAction("CheckMeter");
                    }
                }

                return RedirectToAction("SelectDateTime");

            }
            catch
            {
                return View();
            }
        }
        [HttpGet]
        public ActionResult ResultRemarkIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ResultRemarkRepo resultRemarkRepo = new ResultRemarkRepo();
            IEnumerable<ResultRemarkModels> resultRemarks = resultRemarkRepo.GetResultRemark().Where(r => r.TitleResultId == 1);
            if (isFitter)
            {
                resultRemarks = resultRemarks.Where(r => r.ResultRemarkTh != "ผลการล้างแก้ว ดี");
            }

            string selectResultRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in resultRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.ResultRemarkTh == selectResultRemark),
                                                          Text = r.ResultRemarkTh,
                                                          Value = r.ResultRemarkTh.ToString()
                                                      };

            var access = new AccessModels
           {
               ResultRemarksI = resultRemarks,
               ResultRemarkISelect = selectlistI
           };
            return View(access);

        }



        [HttpGet]
        public ActionResult ResultRemarkIIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ResultRemarkRepo resultRemarkRepo = new ResultRemarkRepo();
            IEnumerable<ResultRemarkModels> resultRemarks = resultRemarkRepo.GetResultRemark().Where(r => r.TitleResultId == 2);
            if (isFitter)
            {
                resultRemarks = resultRemarks.Where(r => r.ResultRemarkTh != "ผลการล้างถ้วย ดี  สะอาด");
            }

            string selectResultRemark = "";
            IEnumerable<SelectListItem> selectlistII = from r in resultRemarks
                                                       select new SelectListItem
                                                       {
                                                           Selected = (r.ResultRemarkTh == selectResultRemark),
                                                           Text = r.ResultRemarkTh,
                                                           Value = r.ResultRemarkTh.ToString()
                                                       };

            var access = new AccessModels
           {
               ResultRemarksII = resultRemarks,
               ResultRemarkIISelect = selectlistII
           };
            return View(access);

        }


        [HttpGet]
        public ActionResult ResultRemarkIIIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ResultRemarkRepo resultRemarkRepo = new ResultRemarkRepo();
            IEnumerable<ResultRemarkModels> resultRemarks = resultRemarkRepo.GetResultRemark().Where(r => r.TitleResultId == 3);
            if (isFitter)
            {
                resultRemarks = resultRemarks.Where(r => r.ResultRemarkTh != "ผลการล้างจาน  ดี  สะอาด");
            }

            string selectResultRemark = "";
            IEnumerable<SelectListItem> selectlistIII = from r in resultRemarks
                                                        select new SelectListItem
                                                        {
                                                            Selected = (r.ResultRemarkTh == selectResultRemark),
                                                            Text = r.ResultRemarkTh,
                                                            Value = r.ResultRemarkTh.ToString()
                                                        };

            var access = new AccessModels
            {
                ResultRemarksIII = resultRemarks,
                ResultRemarkIIISelect = selectlistIII
            };
            return View(access);

        }

        [HttpGet]
        public ActionResult ResultRemarkIVProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ResultRemarkRepo resultRemarkRepo = new ResultRemarkRepo();
            IEnumerable<ResultRemarkModels> resultRemarks = resultRemarkRepo.GetResultRemark().Where(r => r.TitleResultId == 4);
            if (isFitter)
            {
                resultRemarks = resultRemarks.Where(r => r.ResultRemarkTh != "ผลการล้างมีด /ช้อน / ส้อม  ดี  สะอาด");
            }

            string selectResultRemark = "";
            IEnumerable<SelectListItem> selectlistIV = from r in resultRemarks
                                                       select new SelectListItem
                                                       {
                                                           Selected = (r.ResultRemarkTh == selectResultRemark),
                                                           Text = r.ResultRemarkTh,
                                                           Value = r.ResultRemarkTh.ToString()
                                                       };

            var access = new AccessModels
            {
                ResultRemarksIV = resultRemarks,
                ResultRemarkIVSelect = selectlistIV
            };
            return View(access);

        }

        [HttpGet]
        public ActionResult ResultRemarkVProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ResultRemarkRepo resultRemarkRepo = new ResultRemarkRepo();
            IEnumerable<ResultRemarkModels> resultRemarks = resultRemarkRepo.GetResultRemark().Where(r => r.TitleResultId == 5);
            if (isFitter)
            {
                resultRemarks = resultRemarks.Where(r => r.ResultRemarkTh != "ผลการล้างถาด  ดี  สะอาด");
            }

            string selectResultRemark = "";
            IEnumerable<SelectListItem> selectlistV = from r in resultRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.ResultRemarkTh == selectResultRemark),
                                                          Text = r.ResultRemarkTh,
                                                          Value = r.ResultRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                ResultRemarksV = resultRemarks,
                ResultRemarkVSelect = selectlistV
            };
            return View(access);

        }

        public ActionResult CheckMeter()
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            AccessRepo accessRepo = new AccessRepo();
            AccessModels access = accessRepo.GetVisitTemp((string)Session["User"]);

            MachineRepo machineRepo = new MachineRepo();
            MachineModels machine = machineRepo.GetMachineById(access.SerialNo);
            access.PreviousCount = machine.last_meter_no;

            return View(access);
        }

        [HttpPost]
        public ActionResult CheckMeter(FormCollection collecton)
        {
            try
            {
                if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                AccessRepo accessRepo = new AccessRepo();
                AccessModels access = new AccessModels();
                access.PresentCount = Convert.ToInt32(collecton["PresentCount"]);
                access.CreateBy = (string)Session["User"];
                bool result = accessRepo.UpdateMeter(access);

                if (result)
                {
                    return RedirectToAction("ResultRemark");

                }
                return RedirectToAction("CheckMeter");

            }
            catch
            {
                return View();
            }
        }

        public ActionResult ResultRemark()
        {
            //ResultRemarkRepo resultRemarkRepo = new ResultRemarkRepo();
            //IEnumerable<ResultRemarkModels> resultRemarks = resultRemarkRepo.GetResultRemark();

            //string selectResultRemark = "";
            //IEnumerable<SelectListItem> selectlistI = from r in resultRemarks.Where(r => r.TitleResultId == 1)
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.ResultRemarkTh == selectResultRemark),
            //                                              Text = r.ResultRemarkTh,
            //                                              Value = r.ResultRemarkTh.ToString()
            //                                          };
            //IEnumerable<SelectListItem> selectlistII = from r in resultRemarks.Where(r => r.TitleResultId == 2)
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.ResultRemarkTh == selectResultRemark),
            //                                               Text = r.ResultRemarkTh,
            //                                               Value = r.ResultRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistIII = from r in resultRemarks.Where(r => r.TitleResultId == 3)
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.ResultRemarkTh == selectResultRemark),
            //                                                Text = r.ResultRemarkTh,
            //                                                Value = r.ResultRemarkTh.ToString()
            //                                            };
            //IEnumerable<SelectListItem> selectlistIV = from r in resultRemarks.Where(r => r.TitleResultId == 4)
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.ResultRemarkTh == selectResultRemark),
            //                                               Text = r.ResultRemarkTh,
            //                                               Value = r.ResultRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistV = from r in resultRemarks.Where(r => r.TitleResultId == 5)
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.ResultRemarkTh == selectResultRemark),
            //                                              Text = r.ResultRemarkTh,
            //                                              Value = r.ResultRemarkTh.ToString()
            //                                          };


            //var access = new AccessModels
            //{
            //    ResultRemarksI = resultRemarks.Where(r => r.TitleResultId == 1),
            //    ResultRemarkISelect = selectlistI
            // ,
            //    ResultRemarksII = resultRemarks.Where(r => r.TitleResultId == 2),
            //    ResultRemarkIISelect = selectlistII
            //  ,
            //    ResultRemarksIII = resultRemarks.Where(r => r.TitleResultId == 3),
            //    ResultRemarkIIISelect = selectlistIII
            //  ,
            //    ResultRemarksIV = resultRemarks.Where(r => r.TitleResultId == 4),
            //    ResultRemarkIVSelect = selectlistIV
            //  ,
            //    ResultRemarksV = resultRemarks.Where(r => r.TitleResultId == 5),
            //    ResultRemarkVSelect = selectlistV
            //};

            var access = new AccessModels();
            return View();
        }

        [HttpPost]
        public ActionResult ResultRemark(FormCollection collecton)
        {
            try
            {
                if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                // TODO: Add update logic here
                AccessRepo accessRepo = new AccessRepo();
                AccessModels access = new AccessModels();
                access.TitleResultName_I = "Glasses แก้ว";
                access.SoilRemovalBit_I = Convert.ToBoolean(collecton["SoilRemovalBit_I"].Split(',')[0]);
                access.FilmStreakBit_I = Convert.ToBoolean(collecton["FilmStreakBit_I"].Split(',')[0]);
                access.SpottedBit_I = Convert.ToBoolean(collecton["SpottedBit_I"].Split(',')[0]);
                access.ResultRemarkTh_I = Convert.ToString(collecton["ResultRemarksI"] == null ? "ผลการล้างแก้ว ดี" : Convert.ToString(collecton["ResultRemarksI"]));
                access.ResultRemarkEng_I = Convert.ToString(collecton["ResultRemarksI"] == null ? "ผลการล้างแก้ว ดี" : Convert.ToString(collecton["ResultRemarksI"]));
                access.ResultRemarkPointI = Convert.ToInt32(collecton["ResultRemarkPointI"]);

                access.TitleResultName_II = "Cup ถ้วย";
                access.SoilRemovalBit_II = Convert.ToBoolean(collecton["SoilRemovalBit_II"].Split(',')[0]);
                access.FilmStreakBit_II = Convert.ToBoolean(collecton["FilmStreakBit_II"].Split(',')[0]);
                access.SpottedBit_II = Convert.ToBoolean(collecton["SpottedBit_II"].Split(',')[0]);
                access.ResultRemarkTh_II = Convert.ToString(collecton["ResultRemarksII"] == null ? "ผลการล้างถ้วย ดี  สะอาด" : Convert.ToString(collecton["ResultRemarksII"]));
                access.ResultRemarkEng_II = Convert.ToString(collecton["ResultRemarksII"] == null ? "ผลการล้างถ้วย ดี  สะอาด" : Convert.ToString(collecton["ResultRemarksII"]));
                access.ResultRemarkPointII = Convert.ToInt32(collecton["ResultRemarkPointII"]);

                access.TitleResultName_III = "Plates จาน";
                access.SoilRemovalBit_III = Convert.ToBoolean(collecton["SoilRemovalBit_III"].Split(',')[0]);
                access.FilmStreakBit_III = Convert.ToBoolean(collecton["FilmStreakBit_III"].Split(',')[0]);
                access.SpottedBit_III = Convert.ToBoolean(collecton["SpottedBit_III"].Split(',')[0]);
                access.ResultRemarkTh_III = Convert.ToString(collecton["ResultRemarksIII"] == null ? "ผลการล้างถ้วย ดี  สะอาด" : Convert.ToString(collecton["ResultRemarksIII"]));
                access.ResultRemarkEng_III = Convert.ToString(collecton["ResultRemarksIII"] == null ? "ผลการล้างถ้วย ดี  สะอาด" : Convert.ToString(collecton["ResultRemarksIII"]));
                access.ResultRemarkPointIII = Convert.ToInt32(collecton["ResultRemarkPointIII"]);


                access.TitleResultName_IV = "Flatware มีด/ช้อน/ส้อม";
                access.SoilRemovalBit_IV = Convert.ToBoolean(collecton["SoilRemovalBit_IV"].Split(',')[0]);
                access.FilmStreakBit_IV = Convert.ToBoolean(collecton["FilmStreakBit_IV"].Split(',')[0]);
                access.SpottedBit_IV = Convert.ToBoolean(collecton["SpottedBit_IV"].Split(',')[0]);
                access.ResultRemarkTh_IV = Convert.ToString(collecton["ResultRemarksIV"] == null ? "ผลการล้างถ้วย ดี  สะอาด" : Convert.ToString(collecton["ResultRemarksIV"]));
                access.ResultRemarkEng_IV = Convert.ToString(collecton["ResultRemarksIV"] == null ? "ผลการล้างถ้วย ดี  สะอาด" : Convert.ToString(collecton["ResultRemarksIV"]));
                access.ResultRemarkPointIV = Convert.ToInt32(collecton["ResultRemarkPointIV"]);

                access.TitleResultName_V = "Tray ถาด";
                access.SoilRemovalBit_V = Convert.ToBoolean(collecton["SoilRemovalBit_V"].Split(',')[0]);
                access.FilmStreakBit_V = Convert.ToBoolean(collecton["FilmStreakBit_V"].Split(',')[0]);
                access.SpottedBit_V = Convert.ToBoolean(collecton["SpottedBit_V"].Split(',')[0]);
                access.ResultRemarkTh_V = Convert.ToString(collecton["ResultRemarksV"] == null ? "ผลการล้างถ้วย ดี  สะอาด" : Convert.ToString(collecton["ResultRemarksV"]));
                access.ResultRemarkEng_V = Convert.ToString(collecton["ResultRemarksV"] == null ? "ผลการล้างถ้วย ดี  สะอาด" : Convert.ToString(collecton["ResultRemarksV"]));
                access.ResultRemarkPointV = Convert.ToInt32(collecton["ResultRemarkPointV"]);

                access.CreateBy = (string)Session["User"];
                bool result = accessRepo.UpdateResultRemark(access);

                if (result)
                {
                    return RedirectToAction("PROCEDURE");

                }
                return View();
            }
            catch
            {
                return View();
            }
        }

        public ActionResult PROCEDURE()
        {

            //ProcedureRemarkRepo procedureRemarkRepo = new ProcedureRemarkRepo();
            //IEnumerable<ProcedureRemarkModels> procedureRemarks = procedureRemarkRepo.GetProcedureRemark();

            //string selectProcedureRemark = "";
            //IEnumerable<SelectListItem> selectlistI = from r in procedureRemarks.Where(r => r.TitleProcedureId == 1)
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
            //                                              Text = r.ProcedureRemarkTh,
            //                                              Value = r.ProcedureRemarkTh.ToString()
            //                                          };
            //IEnumerable<SelectListItem> selectlistII = from r in procedureRemarks.Where(r => r.TitleProcedureId == 2)
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
            //                                               Text = r.ProcedureRemarkTh,
            //                                               Value = r.ProcedureRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistIII = from r in procedureRemarks.Where(r => r.TitleProcedureId == 3)
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
            //                                                Text = r.ProcedureRemarkTh,
            //                                                Value = r.ProcedureRemarkTh.ToString()
            //                                            };
            //IEnumerable<SelectListItem> selectlistIV = from r in procedureRemarks.Where(r => r.TitleProcedureId == 4)
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
            //                                               Text = r.ProcedureRemarkTh,
            //                                               Value = r.ProcedureRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistV = from r in procedureRemarks.Where(r => r.TitleProcedureId == 5)
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
            //                                              Text = r.ProcedureRemarkTh,
            //                                              Value = r.ProcedureRemarkTh.ToString()
            //                                          };


            //var access = new AccessModels
            //{
            //    ProcedureRemarksI = procedureRemarks.Where(r => r.TitleProcedureId == 1),
            //    ProcedureRemarkISelect = selectlistI
            // ,
            //    ProcedureRemarksII = procedureRemarks.Where(r => r.TitleProcedureId == 2),
            //    ProcedureRemarkIISelect = selectlistII
            //  ,
            //    ProcedureRemarksIII = procedureRemarks.Where(r => r.TitleProcedureId == 3),
            //    ProcedureRemarkIIISelect = selectlistIII
            //  ,
            //    ProcedureRemarksIV = procedureRemarks.Where(r => r.TitleProcedureId == 4),
            //    ProcedureRemarkIVSelect = selectlistIV
            //  ,
            //    ProcedureRemarksV = procedureRemarks.Where(r => r.TitleProcedureId == 5),
            //    ProcedureRemarkVSelect = selectlistV
            //};

            var access = new AccessModels
            {
                ProcedureCheckI = true,
                ProcedureCheckII = true,
                ProcedureCheckIII = true,
                ProcedureCheckIV = true,
                ProcedureCheckV = true
            };
            return View(access);
        }

        [HttpPost]
        public ActionResult PROCEDURE(FormCollection collecton)
        {
            try
            {
                if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                // TODO: Add update logic here
                AccessRepo accessRepo = new AccessRepo();
                AccessModels access = new AccessModels();
                access.TitlePrecedureNameI = "Prescrapping การปาดเศษอาหาร";
                access.ProcedureCheckI = Convert.ToBoolean(collecton["ProcedureCheckI"].Split(',')[0]);
                access.PredureRemarkThI = Convert.ToString(collecton["ProcedureRemarksI"] == null ? "การปาดเศษอาหารดี ไม่มีคราบอาหาร บนภาชนะก่อนนำเข้าเครื่องล้างจาน" : Convert.ToString(collecton["ProcedureRemarksI"]));
                access.PredureRemarkEnI = Convert.ToString(collecton["ProcedureRemarksI"] == null ? "การปาดเศษอาหารดี ไม่มีคราบอาหาร บนภาชนะก่อนนำเข้าเครื่องล้างจาน" : Convert.ToString(collecton["ProcedureRemarksI"]));
                access.ProcedureRemarkPointI = Convert.ToInt32(collecton["ProcedureRemarkPointI"]);

                access.TitlePrecedureNameII = "Racking การเรียงจาน/ภาชนะ/ช้อนลงกระบะ";
                access.ProcedureCheckII = Convert.ToBoolean(collecton["ProcedureCheckII"].Split(',')[0]);
                access.PredureRemarkThII = Convert.ToString(collecton["ProcedureRemarksII"] == null ? "มีการเรียงจาน / ภาชนะ / ช้อน  ดี" : Convert.ToString(collecton["ProcedureRemarksII"]));
                access.PredureRemarkEnII = Convert.ToString(collecton["ProcedureRemarksII"] == null ? "มีการเรียงจาน / ภาชนะ / ช้อน  ดี" : Convert.ToString(collecton["ProcedureRemarksII"]));
                access.ProcedureRemarkPointII = Convert.ToInt32(collecton["ProcedureRemarkPointII"]);

                access.TitlePrecedureNameIII = "Machine Set up/Cleaning การติดตั้ง/ทำความสะอาดเครื่องล้างจาน";
                access.ProcedureCheckIII = Convert.ToBoolean(collecton["ProcedureCheckIII"].Split(',')[0]);
                access.PredureRemarkThIII = Convert.ToString(collecton["ProcedureRemarksIII"] == null ? "มีการติดตั้งการใช้งงานเครื่องล้างจาน ใช้งานได้อย่างเหมาะสม รวมถึง การทำความสะอาดเครื่องล้างจาน หลังการใช้งานดี" : Convert.ToString(collecton["ProcedureRemarksIII"]));
                access.PredureRemarkEnIII = Convert.ToString(collecton["ProcedureRemarksIII"] == null ? "มีการติดตั้งการใช้งงานเครื่องล้างจาน ใช้งานได้อย่างเหมาะสม รวมถึง การทำความสะอาดเครื่องล้างจาน หลังการใช้งานดี" : Convert.ToString(collecton["ProcedureRemarksIII"]));
                access.ProcedureRemarkPointIII = Convert.ToInt32(collecton["ProcedureRemarkPointIII"]);

                access.TitlePrecedureNameIV = "Flatware Presoaking การแช่ มีด/ช้อน/ซ่อม";
                access.ProcedureCheckIV = Convert.ToBoolean(collecton["ProcedureCheckIV"].Split(',')[0]);
                access.PredureRemarkThIV = Convert.ToString(collecton["ProcedureRemarksIV"] == null ? "มีการแช่ มีด  ช้อน ส้อม เพื่อให้คราบอาหารที่สะสม อ่อนตัว ก่อนนำเข้าเครื่องล้างจาน" : Convert.ToString(collecton["ProcedureRemarksIV"]));
                access.PredureRemarkEnIV = Convert.ToString(collecton["ProcedureRemarksIV"] == null ? "มีการแช่ มีด  ช้อน ส้อม เพื่อให้คราบอาหารที่สะสม อ่อนตัว ก่อนนำเข้าเครื่องล้างจาน" : Convert.ToString(collecton["ProcedureRemarksIV"]));
                access.ProcedureRemarkPointIV = Convert.ToInt32(collecton["ProcedureRemarkPointIV"]);

                access.TitlePrecedureNameV = "Change Tank Water การเปลี่ยนน้ำใหม่";
                access.ProcedureCheckV = Convert.ToBoolean(collecton["ProcedureCheckV"].Split(',')[0]);
                access.PredureRemarkThV = Convert.ToString(collecton["ProcedureRemarksV"] == null ? "มีการเปลี่ยนน้ำใหม่ ระหว่างวัน อย่างสม่ำเสมอ" : Convert.ToString(collecton["ProcedureRemarksV"]));
                access.PredureRemarkEnV = Convert.ToString(collecton["ProcedureRemarksV"] == null ? "มีการเปลี่ยนน้ำใหม่ ระหว่างวัน อย่างสม่ำเสมอ" : Convert.ToString(collecton["ProcedureRemarksV"]));
                access.ProcedureRemarkPointV = Convert.ToInt32(collecton["ProcedureRemarkPointV"]);

                access.CreateBy = (string)Session["User"];

                bool result = accessRepo.UpdateProcedure(access);

                if (result)
                {
                    return RedirectToAction("WASHFACTORS");

                }
                return View();
            }
            catch
            {
                return View();
            }
        }


        [HttpGet]
        public ActionResult ProcedureRemarkIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ProcedureRemarkRepo procedureRemarkRepo = new ProcedureRemarkRepo();
            IEnumerable<ProcedureRemarkModels> procedureRemarks = procedureRemarkRepo.GetProcedureRemark().Where(r => r.TitleProcedureId == 1); ;
            if (isFitter)
            {
                procedureRemarks = procedureRemarks.Where(r => r.ProcedureRemarkTh != "การปาดเศษอาหารดี ไม่มีคราบอาหาร บนภาชนะก่อนนำเข้าเครื่องล้างจาน");
            }

            string selectProcedureRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in procedureRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
                                                          Text = r.ProcedureRemarkTh,
                                                          Value = r.ProcedureRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                ProcedureRemarksI = procedureRemarks,
                ProcedureRemarkISelect = selectlistI
            };
            return View(access);

        }

        [HttpGet]
        public ActionResult ProcedureRemarkIIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ProcedureRemarkRepo procedureRemarkRepo = new ProcedureRemarkRepo();
            IEnumerable<ProcedureRemarkModels> procedureRemarks = procedureRemarkRepo.GetProcedureRemark().Where(r => r.TitleProcedureId == 2); ;
            if (isFitter)
            {
                procedureRemarks = procedureRemarks.Where(r => r.ProcedureRemarkTh != "มีการเรียงจาน / ภาชนะ / ช้อน  ดี");
            }

            string selectProcedureRemark = "";
            IEnumerable<SelectListItem> selectlistII = from r in procedureRemarks
                                                       select new SelectListItem
                                                       {
                                                           Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
                                                           Text = r.ProcedureRemarkTh,
                                                           Value = r.ProcedureRemarkTh.ToString()
                                                       };

            var access = new AccessModels
            {
                ProcedureRemarksII = procedureRemarks,
                ProcedureRemarkIISelect = selectlistII
            };
            return View(access);

        }
        [HttpGet]
        public ActionResult ProcedureRemarkIIIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ProcedureRemarkRepo procedureRemarkRepo = new ProcedureRemarkRepo();
            IEnumerable<ProcedureRemarkModels> procedureRemarks = procedureRemarkRepo.GetProcedureRemark().Where(r => r.TitleProcedureId == 3); ;
            if (isFitter)
            {
                procedureRemarks = procedureRemarks.Where(r => r.ProcedureRemarkTh != "มีการติดตั้งการใช้งงานเครื่องล้างจาน ใช้งานได้อย่างเหมาะสม รวมถึง การทำความสะอาดเครื่องล้างจาน หลังการใช้งานดี");
            }

            string selectProcedureRemark = "";
            IEnumerable<SelectListItem> selectlistIII = from r in procedureRemarks
                                                        select new SelectListItem
                                                        {
                                                            Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
                                                            Text = r.ProcedureRemarkTh,
                                                            Value = r.ProcedureRemarkTh.ToString()
                                                        };

            var access = new AccessModels
            {
                ProcedureRemarksIII = procedureRemarks,
                ProcedureRemarkIIISelect = selectlistIII
            };
            return View(access);

        }

        [HttpGet]
        public ActionResult ProcedureRemarkIVProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ProcedureRemarkRepo procedureRemarkRepo = new ProcedureRemarkRepo();
            IEnumerable<ProcedureRemarkModels> procedureRemarks = procedureRemarkRepo.GetProcedureRemark().Where(r => r.TitleProcedureId == 4); ;
            if (isFitter)
            {
                procedureRemarks = procedureRemarks.Where(r => r.ProcedureRemarkTh != "มีการแช่ มีด  ช้อน ส้อม เพื่อให้คราบอาหารที่สะสม อ่อนตัว ก่อนนำเข้าเครื่องล้างจาน");
            }

            string selectProcedureRemark = "";
            IEnumerable<SelectListItem> selectlistIV = from r in procedureRemarks
                                                       select new SelectListItem
                                                       {
                                                           Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
                                                           Text = r.ProcedureRemarkTh,
                                                           Value = r.ProcedureRemarkTh.ToString()
                                                       };

            var access = new AccessModels
            {
                ProcedureRemarksIV = procedureRemarks,
                ProcedureRemarkIVSelect = selectlistIV
            };
            return View(access);

        }

        [HttpGet]
        public ActionResult ProcedureRemarkVProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ProcedureRemarkRepo procedureRemarkRepo = new ProcedureRemarkRepo();
            IEnumerable<ProcedureRemarkModels> procedureRemarks = procedureRemarkRepo.GetProcedureRemark().Where(r => r.TitleProcedureId == 5); ;
            if (isFitter)
            {
                procedureRemarks = procedureRemarks.Where(r => r.ProcedureRemarkTh != "มีการเปลี่ยนน้ำใหม่ ระหว่างวัน อย่างสม่ำเสมอ");
            }

            string selectProcedureRemark = "";
            IEnumerable<SelectListItem> selectlistV = from r in procedureRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.ProcedureRemarkTh == selectProcedureRemark),
                                                          Text = r.ProcedureRemarkTh,
                                                          Value = r.ProcedureRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                ProcedureRemarksV = procedureRemarks,
                ProcedureRemarkVSelect = selectlistV
            };
            return View(access);

        }

        public ActionResult WASHFACTORS()
        {
            //WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            //IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark();

            //string selectWashFactorRemark = "";
            //IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ")
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                              Text = r.WashFactorRemarkTh,
            //                                              Value = r.WashFactorRemarkTh.ToString()
            //                                          };
            //IEnumerable<SelectListItem> selectlistII = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                               Text = r.WashFactorRemarkTh,
            //                                               Value = r.WashFactorRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistIII = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ")
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                                Text = r.WashFactorRemarkTh,
            //                                                Value = r.WashFactorRemarkTh.ToString()
            //                                            };
            //IEnumerable<SelectListItem> selectlistIV = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                               Text = r.WashFactorRemarkTh,
            //                                               Value = r.WashFactorRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistV = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ")
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                              Text = r.WashFactorRemarkTh,
            //                                              Value = r.WashFactorRemarkTh.ToString()
            //                                          };

            //IEnumerable<SelectListItem> selectlistVI = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                               Text = r.WashFactorRemarkTh,
            //                                               Value = r.WashFactorRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistVII = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา")
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                                Text = r.WashFactorRemarkTh,
            //                                                Value = r.WashFactorRemarkTh.ToString()
            //                                            };
            //IEnumerable<SelectListItem> selectlistVIII = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา")
            //                                             select new SelectListItem
            //                                             {
            //                                                 Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                                 Text = r.WashFactorRemarkTh,
            //                                                 Value = r.WashFactorRemarkTh.ToString()
            //                                             };
            //IEnumerable<SelectListItem> selectlistIX = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                               Text = r.WashFactorRemarkTh,
            //                                               Value = r.WashFactorRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistX = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา")
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                              Text = r.WashFactorRemarkTh,
            //                                              Value = r.WashFactorRemarkTh.ToString()
            //                                          };

            //IEnumerable<SelectListItem> selectlistXI = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ความกระด้าง")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                               Text = r.WashFactorRemarkTh,
            //                                               Value = r.WashFactorRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistXII = from r in washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ")
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
            //                                                Text = r.WashFactorRemarkTh,
            //                                                Value = r.WashFactorRemarkTh.ToString()
            //                                            };

            //var access = new AccessModels
            //{
            //    WashFactorRemarksI = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ"),
            //    WashFactorRemarkISelect = selectlistI
            // ,
            //    WashFactorRemarksII = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ"),
            //    WashFactorRemarkIISelect = selectlistII
            // ,
            //    WashFactorRemarksIII = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ"),
            //    WashFactorRemarkIIISelect = selectlistIII
            // ,
            //    WashFactorRemarksIV = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ"),
            //    WashFactorRemarkIVSelect = selectlistIV
            // ,
            //    WashFactorRemarksV = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ"),
            //    WashFactorRemarkVSelect = selectlistV
            // ,
            //    WashFactorRemarksVI = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา"),
            //    WashFactorRemarkVISelect = selectlistVI
            //  ,
            //    WashFactorRemarksVII = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา"),
            //    WashFactorRemarkVIISelect = selectlistVII
            //  ,
            //    WashFactorRemarksVIII = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา"),
            //    WashFactorRemarkVIIISelect = selectlistVIII
            //  ,
            //    WashFactorRemarksIX = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา"),
            //    WashFactorRemarkIXSelect = selectlistIX
            //  ,
            //    WashFactorRemarksX = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา"),
            //    WashFactorRemarkXSelect = selectlistX
            //  ,
            //    WashFactorRemarksXI = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "ความกระด้าง"),
            //    WashFactorRemarkXISelect = selectlistXI
            //    ,
            //    WashFactorRemarksXII = washFactorActorRemarks.Where(r => r.TitleWashFactorsType == "อุณหภูมิ"),
            //    WashFactorRemarkXIISelect = selectlistXII
            //};

            var access = new AccessModels();
            return View(access);
        }

        [HttpPost]
        public ActionResult WASHFACTORS(FormCollection collecton)
        {
            try
            {
                {
                    if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                    // TODO: Add update logic here
                    AccessRepo accessRepo = new AccessRepo();
                    AccessModels access = new AccessModels();
                    access.TitleWashFactorNameI = "Wash Temp อุณหภูมิน้ำล้างคราบไขมัน(oC) Glass Washer 50-55C";
                    access.ActualI = Convert.ToString(collecton["ActualI"]);
                    if (access.ActualI == "NA")
                    {
                        access.WashFactorRemarkThI = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnI = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThI = Convert.ToString(collecton["WashFactorRemarksI"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksI"]));
                        access.WashFactorRemarkEnI = Convert.ToString(collecton["WashFactorRemarksI"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksI"]));
                    }
                    access.ActualPointI = Convert.ToInt32(collecton["ActualPointI"]);

                    access.TitleWashFactorNameII = "Wash Temp อุณหภูมิน้ำล้างคราบไขมัน(oC) Dish Washer 60-65 C";
                    access.ActualII = Convert.ToString(collecton["ActualII"]);
                    if (access.ActualII == "NA")
                    {
                        access.WashFactorRemarkThII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThII = Convert.ToString(collecton["WashFactorRemarksII"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksII"]));
                        access.WashFactorRemarkEnII = Convert.ToString(collecton["WashFactorRemarksII"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksII"]));
                    }
                    access.ActualPointII = Convert.ToInt32(collecton["ActualPointII"]);

                    access.TitleWashFactorNameIII = "Final Rinse Temp อุณหภูมิน้ำเคลือบแห้งสุดท้าย (oC) High Temp Final Rinse 80-85 C";
                    access.ActualIII = Convert.ToString(collecton["ActualIII"]);
                    if (access.ActualIII == "NA")
                    {
                        access.WashFactorRemarkThIII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnIII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThIII = Convert.ToString(collecton["WashFactorRemarksIII"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksIII"]));
                        access.WashFactorRemarkEnIII = Convert.ToString(collecton["WashFactorRemarksIII"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksIII"]));
                    }
                    access.ActualPointIII = Convert.ToInt32(collecton["ActualPointIII"]);

                    access.TitleWashFactorNameIV = "Final Rinse Temp อุณหภูมิน้ำเคลือบแห้งสุดท้าย (oC) Low Temp Final Rinse 60-65 C";
                    access.ActualIV = Convert.ToString(collecton["ActualIV"]);
                    if (access.ActualIV == "NA")
                    {
                        access.WashFactorRemarkThIV = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnIV = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThIV = Convert.ToString(collecton["WashFactorRemarksIV"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksIV"]));
                        access.WashFactorRemarkEnIV = Convert.ToString(collecton["WashFactorRemarksIV"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksIV"]));
                    }
                    access.ActualPointIV = Convert.ToInt32(collecton["ActualPointIV"]);

                    access.TitleWashFactorNameV = "Final Rinse Temp อุณหภูมิน้ำเคลือบแห้งสุดท้าย (oC) Glass Washer 70-75 C";
                    access.ActualV = Convert.ToString(collecton["ActualV"]);
                    if (access.ActualV == "NA")
                    {
                        access.WashFactorRemarkThV = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnV = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThV = Convert.ToString(collecton["WashFactorRemarksV"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksV"]));
                        access.WashFactorRemarkEnV = Convert.ToString(collecton["WashFactorRemarksV"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksV"]));
                    }
                    access.ActualPointV = Convert.ToInt32(collecton["ActualPointV"]);

                    access.TitleWashFactorNameVI = "Detergent Conc (ppm) ปริมาณน้ำยาล้างจาน Glass Washer  1-4ml/L";
                    access.ActualVI = Convert.ToString(collecton["ActualVI"]);
                    if (access.ActualVI == "NA")
                    {
                        access.WashFactorRemarkThVI = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnVI = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThVI = Convert.ToString(collecton["WashFactorRemarksVI"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksVI"]));
                        access.WashFactorRemarkEnVI = Convert.ToString(collecton["WashFactorRemarksVI"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksVI"]));
                    }
                    access.ActualPointVI = Convert.ToInt32(collecton["ActualPointVI"]);

                    access.TitleWashFactorNameVII = "Detergent Conc (ppm) ปริมาณน้ำยาล้างจาน Dish Washer 120-200ppm";
                    access.ActualVII = Convert.ToString(collecton["ActualVII"]);
                    if (access.ActualVII == "NA")
                    {
                        access.WashFactorRemarkThVII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnVII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThVII = Convert.ToString(collecton["WashFactorRemarksVII"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksVII"]));
                        access.WashFactorRemarkEnVII = Convert.ToString(collecton["WashFactorRemarksVII"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksVII"]));
                    }
                    access.ActualPointVII = Convert.ToInt32(collecton["ActualPointVII"]);

                    access.TitleWashFactorNameVIII = "Final Rinse Vol (ml/L) ปริมาณน้ำยาเคลือบแห้ง Glass Washer 0.1-0.3";
                    access.ActualVIII = Convert.ToString(collecton["ActualVIII"]);
                    if (access.ActualVIII == "NA")
                    {
                        access.WashFactorRemarkThVIII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnVIII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThVIII = Convert.ToString(collecton["WashFactorRemarksVIII"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksVIII"]));
                        access.WashFactorRemarkEnVIII = Convert.ToString(collecton["WashFactorRemarksVIII"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksVIII"]));
                    }
                    access.ActualPointVIII = Convert.ToInt32(collecton["ActualPointVIII"]);

                    access.TitleWashFactorNameIX = "Final Rinse Vol (ml/L) ปริมาณน้ำยาเคลือบแห้ง Dish Washer 0.2-0.4";
                    access.ActualIX = Convert.ToString(collecton["ActualIX"]);
                    if (access.ActualIX == "NA")
                    {
                        access.WashFactorRemarkThIX = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnIX = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThIX = Convert.ToString(collecton["WashFactorRemarksIX"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksIX"]));
                        access.WashFactorRemarkEnIX = Convert.ToString(collecton["WashFactorRemarksIX"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksIX"]));
                    }
                    access.ActualPointIX = Convert.ToInt32(collecton["ActualPointIX"]);

                    access.TitleWashFactorNameX = "Final Rinse Vol (ml/L) ปริมาณน้ำยาเคลือบแห้ง Low Temp 0.2-0.4";
                    access.ActualX = Convert.ToString(collecton["ActualX"]);
                    if (access.ActualX == "NA")
                    {
                        access.WashFactorRemarkThX = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnX = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThX = Convert.ToString(collecton["WashFactorRemarksX"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksX"]));
                        access.WashFactorRemarkEnX = Convert.ToString(collecton["WashFactorRemarksX"] == null ? "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ" : Convert.ToString(collecton["WashFactorRemarksX"]));
                    }
                    access.ActualPointX = Convert.ToInt32(collecton["ActualPointX"]);

                    access.TitleWashFactorNameXI = "Water Hardness (ppm) ความกระด้างของน้ำ Desired ค่าต้องการ";
                    access.ActualXI = Convert.ToString(collecton["ActualXI"]);
                    if (access.ActualXI == "NA")
                    {
                        access.WashFactorRemarkThXI = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnXI = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThXI = Convert.ToString(collecton["WashFactorRemarksXI"] == null ? "ค่าความกระด้างของน้ำอยู่ในเกณฑ์ปกติ น้ำอ่อน" : Convert.ToString(collecton["WashFactorRemarksXI"]));
                        access.WashFactorRemarkEnXI = Convert.ToString(collecton["WashFactorRemarksXI"] == null ? "ค่าความกระด้างของน้ำอยู่ในเกณฑ์ปกติ น้ำอ่อน" : Convert.ToString(collecton["WashFactorRemarksXI"]));
                    }
                    access.ActualPointXI = Convert.ToInt32(collecton["ActualPointXI"]);

                    access.TitleWashFactorNameXII = "Sanitizer Concentration ( ppm) Only Low Temp 40-50";
                    access.ActualXII = Convert.ToString(collecton["ActualXII"]);
                    if (access.ActualXII == "NA")
                    {
                        access.WashFactorRemarkThXII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                        access.WashFactorRemarkEnXII = "ไม่มีเครื่องรุ่นนี้ในระบบ";
                    }
                    else
                    {
                        access.WashFactorRemarkThXII = Convert.ToString(collecton["WashFactorRemarksXII"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksXII"]));
                        access.WashFactorRemarkEnXII = Convert.ToString(collecton["WashFactorRemarksXII"] == null ? "อุณหภูมิอยู่ในช่วงปกติ" : Convert.ToString(collecton["WashFactorRemarksXII"]));
                    }
                    access.ActualPointXII = Convert.ToInt32(collecton["ActualPointXII"]);

                    access.CreateBy = (string)Session["User"];

                    bool result = accessRepo.UpdateWashFactors(access);

                    if (result)
                    {
                        return RedirectToAction("MECHANICAL");

                    }
                    return View();
                }
            }
            catch
            {
                return View();
            }
        }


        [HttpGet]
        public ActionResult WashFactorRemarkIProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "อุณหภูมิ");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "อุณหภูมิอยู่ในช่วงปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "อุณหภูมิอยู่ในช่วงปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksI = washFactorActorRemarks,
                WashFactorRemarkISelect = selectlistI

            };
            return View(access);

        }

        [HttpGet]
        public ActionResult WashFactorRemarkIIProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "อุณหภูมิ");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "อุณหภูมิอยู่ในช่วงปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "อุณหภูมิอยู่ในช่วงปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksII = washFactorActorRemarks,
                WashFactorRemarkIISelect = selectlistI

            };
            return View(access);


        }
        [HttpGet]
        public ActionResult WashFactorRemarkIIIProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "อุณหภูมิ");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "อุณหภูมิอยู่ในช่วงปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "อุณหภูมิอยู่ในช่วงปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksIII = washFactorActorRemarks,
                WashFactorRemarkIIISelect = selectlistI

            };
            return View(access);
        }
        [HttpGet]
        public ActionResult WashFactorRemarkIVProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "อุณหภูมิ");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "อุณหภูมิอยู่ในช่วงปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "อุณหภูมิอยู่ในช่วงปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksIV = washFactorActorRemarks,
                WashFactorRemarkIVSelect = selectlistI

            };
            return View(access);
        }
        [HttpGet]
        public ActionResult WashFactorRemarkVProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "อุณหภูมิ");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "อุณหภูมิอยู่ในช่วงปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "อุณหภูมิอยู่ในช่วงปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksV = washFactorActorRemarks,
                WashFactorRemarkVSelect = selectlistI

            };
            return View(access);
        }
        [HttpGet]
        public ActionResult WashFactorRemarkVIProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksVI = washFactorActorRemarks,
                WashFactorRemarkVISelect = selectlistI

            };
            return View(access);
        }
        [HttpGet]
        public ActionResult WashFactorRemarkVIIProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksVII = washFactorActorRemarks,
                WashFactorRemarkVIISelect = selectlistI

            };
            return View(access);
        }
        [HttpGet]
        public ActionResult WashFactorRemarkVIIIProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksVIII = washFactorActorRemarks,
                WashFactorRemarkVIIISelect = selectlistI

            };
            return View(access);
        }
        [HttpGet]
        public ActionResult WashFactorRemarkIXProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksIX = washFactorActorRemarks,
                WashFactorRemarkIXSelect = selectlistI

            };
            return View(access);
        }
        [HttpGet]
        public ActionResult WashFactorRemarkXProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "ปริมาณน้ำยา");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "ปริมาณน้ำยาอยู่ในเกณฑ์ปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksX = washFactorActorRemarks,
                WashFactorRemarkXSelect = selectlistI

            };
            return View(access);
        }
        [HttpGet]
        public ActionResult WashFactorRemarkXIProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "ความกระด้าง");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ค่าความกระด้างของน้ำอยู่ในเกณฑ์ปกติ น้ำอ่อน");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "ค่าความกระด้างของน้ำอยู่ในเกณฑ์ปกติ น้ำอ่อน");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksXI = washFactorActorRemarks,
                WashFactorRemarkXISelect = selectlistI

            };
            return View(access);
        }
        [HttpGet]
        public ActionResult WashFactorRemarkXIIProcess(bool isFitter, bool isNA)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            WashFactorRemarkRepo washFactorRemarkRepo = new WashFactorRemarkRepo();
            IEnumerable<WashFactorRemarkModels> washFactorActorRemarks = washFactorRemarkRepo.GetWashFactorRemark().Where(r => r.TitleWashFactorsType == "อุณหภูมิ");

            if (isNA)
            {

                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "ไม่มีเครื่องรุ่นนี้ในระบบ");
            }
            else if (isFitter)
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh == "อุณหภูมิอยู่ในช่วงปกติ");
            }
            else
            {
                washFactorActorRemarks = washFactorActorRemarks.Where(r => r.WashFactorRemarkTh != "ไม่มีเครื่องรุ่นนี้ในระบบ" && r.WashFactorRemarkTh != "อุณหภูมิอยู่ในช่วงปกติ");
            }

            string selectWashFactorRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in washFactorActorRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.WashFactorRemarkTh == selectWashFactorRemark),
                                                          Text = r.WashFactorRemarkTh,
                                                          Value = r.WashFactorRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                WashFactorRemarksXII = washFactorActorRemarks,
                WashFactorRemarkXIISelect = selectlistI

            };
            return View(access);
        }
        public ActionResult MECHANICAL()
        {

            //MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            //IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark();

            //string selectMechanicalRemark = "";
            //IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์")
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                              Text = r.MechanicalRemarkTh,
            //                                              Value = r.MechanicalRemarkTh.ToString()
            //                                          };
            //IEnumerable<SelectListItem> selectlistII = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                               Text = r.MechanicalRemarkTh,
            //                                               Value = r.MechanicalRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistIII = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "แขนฉีด")
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                                Text = r.MechanicalRemarkTh,
            //                                                Value = r.MechanicalRemarkTh.ToString()
            //                                            };
            //IEnumerable<SelectListItem> selectlistIV = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "แขนฉีด")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                               Text = r.MechanicalRemarkTh,
            //                                               Value = r.MechanicalRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistV = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "ตะแกรงตัก")
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                              Text = r.MechanicalRemarkTh,
            //                                              Value = r.MechanicalRemarkTh.ToString()
            //                                          };

            //IEnumerable<SelectListItem> selectlistVI = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                               Text = r.MechanicalRemarkTh,
            //                                               Value = r.MechanicalRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistVII = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์")
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                                Text = r.MechanicalRemarkTh,
            //                                                Value = r.MechanicalRemarkTh.ToString()
            //                                            };
            //IEnumerable<SelectListItem> selectlistVIII = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์")
            //                                             select new SelectListItem
            //                                             {
            //                                                 Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                                 Text = r.MechanicalRemarkTh,
            //                                                 Value = r.MechanicalRemarkTh.ToString()
            //                                             };
            //IEnumerable<SelectListItem> selectlistIX = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                               Text = r.MechanicalRemarkTh,
            //                                               Value = r.MechanicalRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistX = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "ม่าน")
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                              Text = r.MechanicalRemarkTh,
            //                                              Value = r.MechanicalRemarkTh.ToString()
            //                                          };

            //IEnumerable<SelectListItem> selectlistXI = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์")
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                               Text = r.MechanicalRemarkTh,
            //                                               Value = r.MechanicalRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistXII = from r in mechanicalRemarks.Where(r => r.TitleMechanicalType == "หม้อต้ม")
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
            //                                                Text = r.MechanicalRemarkTh,
            //                                                Value = r.MechanicalRemarkTh.ToString()
            //                                            };

            var access = new AccessModels
            {
                //   MechanicalRemarksI = mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์"),
                //   MechanicalRemarkISelect = selectlistI
                //,
                //   MechanicalRemarksII = mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์"),
                //   MechanicalRemarkIISelect = selectlistII
                //,
                //   MechanicalRemarksIII = mechanicalRemarks.Where(r => r.TitleMechanicalType == "แขนฉีด"),
                //   MechanicalRemarkIIISelect = selectlistIII
                //,
                //   MechanicalRemarksIV = mechanicalRemarks.Where(r => r.TitleMechanicalType == "แขนฉีด"),
                //   MechanicalRemarkIVSelect = selectlistIV
                //,
                //   MechanicalRemarksV = mechanicalRemarks.Where(r => r.TitleMechanicalType == "ตะแกรงตัก"),
                //   MechanicalRemarkVSelect = selectlistV
                //,
                //   MechanicalRemarksVI = mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์"),
                //   MechanicalRemarkVISelect = selectlistVI
                // ,
                //   MechanicalRemarksVII = mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์"),
                //   MechanicalRemarkVIISelect = selectlistVII
                // ,
                //   MechanicalRemarksVIII = mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์"),
                //   MechanicalRemarkVIIISelect = selectlistVIII
                // ,
                //   MechanicalRemarksIX = mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์"),
                //   MechanicalRemarkIXSelect = selectlistIX
                // ,
                //   MechanicalRemarksX = mechanicalRemarks.Where(r => r.TitleMechanicalType == "ม่าน"),
                //   MechanicalRemarkXSelect = selectlistX
                // ,
                //   MechanicalRemarksXI = mechanicalRemarks.Where(r => r.TitleMechanicalType == "อุปกรณ์"),
                //   MechanicalRemarkXISelect = selectlistXI
                //   ,
                //   MechanicalRemarksXII = mechanicalRemarks.Where(r => r.TitleMechanicalType == "หม้อต้ม"),
                //   MechanicalRemarkXIISelect = selectlistXII,

                MechanicalCheckI = true,
                MechanicalCheckII = true,
                MechanicalCheckIII = true,
                MechanicalCheckIV = true,
                MechanicalCheckV = true,
                MechanicalCheckVI = true,
                MechanicalCheckVII = true,
                MechanicalCheckVIII = true,
                MechanicalCheckIX = true,
                MechanicalCheckX = true,
                MechanicalCheckXI = true,
                MechanicalCheckXII = true
            };


            return View(access);
        }

        [HttpPost]
        public ActionResult MECHANICAL(FormCollection collecton)
        {
            try
            {
                {
                    if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                    // TODO: Add update logic here
                    AccessRepo accessRepo = new AccessRepo();
                    AccessModels access = new AccessModels();
                    access.TitleMechanicalNameI = "Pre-Scrap Hose ผักบัวฉีดล้าง";
                    access.MechanicalCheckI = Convert.ToBoolean(collecton["MechanicalCheckI"].Split(',')[0]);
                    access.MechanicalRemarkThI = Convert.ToString(collecton["MechanicalRemarksI"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksI"]));
                    access.MechanicalRemarkEnI = Convert.ToString(collecton["MechanicalRemarksI"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksI"]));
                    access.MechanicalPointI = Convert.ToInt32(collecton["MechanicalPointI"]);

                    access.TitleMechanicalNameII = "Temp Gauges มาตรวัดอุณหภูมิ";
                    access.MechanicalCheckII = Convert.ToBoolean(collecton["MechanicalCheckII"].Split(',')[0]);
                    access.MechanicalRemarkThII = Convert.ToString(collecton["MechanicalRemarksII"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksII"]));
                    access.MechanicalRemarkEnII = Convert.ToString(collecton["MechanicalRemarksII"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksII"]));
                    access.MechanicalPointII = Convert.ToInt32(collecton["MechanicalPointII"]);

                    access.TitleMechanicalNameIII = "Wash Arm/Jets แขนฉีดล้าง";
                    access.MechanicalCheckIII = Convert.ToBoolean(collecton["MechanicalCheckIII"].Split(',')[0]);
                    access.MechanicalRemarkThIII = Convert.ToString(collecton["MechanicalRemarksIII"] == null ? "อุปกรณ์ใช้งานได้ดี ไม่มีการอุดตันของแขนฉีด" : Convert.ToString(collecton["MechanicalRemarksIII"]));
                    access.MechanicalRemarkEnIII = Convert.ToString(collecton["MechanicalRemarksIII"] == null ? "อุปกรณ์ใช้งานได้ดี ไม่มีการอุดตันของแขนฉีด" : Convert.ToString(collecton["MechanicalRemarksIII"]));
                    access.MechanicalPointIII = Convert.ToInt32(collecton["MechanicalPointIII"]);

                    access.TitleMechanicalNameIV = "Rinse Arm/Jets แขนฉีดรินซ์";
                    access.MechanicalCheckIV = Convert.ToBoolean(collecton["MechanicalCheckIV"].Split(',')[0]);
                    access.MechanicalRemarkThIV = Convert.ToString(collecton["MechanicalRemarksIV"] == null ? "อุปกรณ์ใช้งานได้ดี ไม่มีการอุดตันของแขนฉีด" : Convert.ToString(collecton["MechanicalRemarksIV"]));
                    access.MechanicalRemarkEnIV = Convert.ToString(collecton["MechanicalRemarksIV"] == null ? "อุปกรณ์ใช้งานได้ดี ไม่มีการอุดตันของแขนฉีด" : Convert.ToString(collecton["MechanicalRemarksIV"]));
                    access.MechanicalPointIV = Convert.ToInt32(collecton["MechanicalPointIV"]);

                    access.TitleMechanicalNameV = "Scrap Trays ตะแกรงตักเศษอาหาร";
                    access.MechanicalCheckV = Convert.ToBoolean(collecton["MechanicalCheckV"].Split(',')[0]);
                    access.MechanicalRemarkThV = Convert.ToString(collecton["MechanicalRemarksV"] == null ? "มีการทำความสะอาด ตะแกรงตักเศษอาหาร ดี ไม่มีเศษอาหารสะสม" : Convert.ToString(collecton["MechanicalRemarksV"]));
                    access.MechanicalRemarkEnV = Convert.ToString(collecton["MechanicalRemarksV"] == null ? "มีการทำความสะอาด ตะแกรงตักเศษอาหาร ดี ไม่มีเศษอาหารสะสม" : Convert.ToString(collecton["MechanicalRemarksV"]));
                    access.MechanicalPointV = Convert.ToInt32(collecton["MechanicalPointV"]);

                    access.TitleMechanicalNameVI = "Drains ท่อน้ำทิ้ง";
                    access.MechanicalCheckVI = Convert.ToBoolean(collecton["MechanicalCheckVI"].Split(',')[0]);
                    access.MechanicalRemarkThVI = Convert.ToString(collecton["MechanicalRemarksVI"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksVI"]));
                    access.MechanicalRemarkEnVI = Convert.ToString(collecton["MechanicalRemarksVI"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksVI"]));
                    access.MechanicalPointVI = Convert.ToInt32(collecton["MechanicalPointVI"]);

                    access.TitleMechanicalNameVII = "Overflow Drain ท่อน้ำล้น";
                    access.MechanicalCheckVII = Convert.ToBoolean(collecton["MechanicalCheckVII"].Split(',')[0]);
                    access.MechanicalRemarkThVII = Convert.ToString(collecton["MechanicalRemarksVII"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksVII"]));
                    access.MechanicalRemarkEnVII = Convert.ToString(collecton["MechanicalRemarksVII"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksVII"]));
                    access.MechanicalPointVII = Convert.ToInt32(collecton["MechanicalPointVII"]);

                    access.TitleMechanicalNameVIII = "Fill Valve วาล์วเติมน้ำ";
                    access.MechanicalCheckVIII = Convert.ToBoolean(collecton["MechanicalCheckVIII"].Split(',')[0]);
                    access.MechanicalRemarkThVIII = Convert.ToString(collecton["MechanicalRemarksVIII"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksVIII"]));
                    access.MechanicalRemarkEnVIII = Convert.ToString(collecton["MechanicalRemarksVIII"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksVIII"]));
                    access.MechanicalPointVIII = Convert.ToInt32(collecton["MechanicalPointVIII"]);

                    access.TitleMechanicalNameIX = "Wash Pump มอเตอร์ปั้ม";
                    access.MechanicalCheckIX = Convert.ToBoolean(collecton["MechanicalCheckIX"].Split(',')[0]);
                    access.MechanicalRemarkThIX = Convert.ToString(collecton["MechanicalRemarksIX"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksIX"]));
                    access.MechanicalRemarkEnIX = Convert.ToString(collecton["MechanicalRemarksIX"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksIX"]));
                    access.MechanicalPointIX = Convert.ToInt32(collecton["MechanicalPointIX"]);

                    access.TitleMechanicalNameX = "Curtain ม่าน";
                    access.MechanicalCheckX = Convert.ToBoolean(collecton["MechanicalCheckX"].Split(',')[0]);
                    access.MechanicalRemarkThX = Convert.ToString(collecton["MechanicalRemarksX"] == null ? "ม่าน อยู่ในสภาพดี" : Convert.ToString(collecton["MechanicalRemarksX"]));
                    access.MechanicalRemarkEnX = Convert.ToString(collecton["MechanicalRemarksX"] == null ? "ม่าน อยู่ในสภาพดี" : Convert.ToString(collecton["MechanicalRemarksX"]));
                    access.MechanicalPointX = Convert.ToInt32(collecton["MechanicalPointX"]);

                    access.TitleMechanicalNameXI = "Final Rinse Valve วาล์วน้ำสุดท้าย";
                    access.MechanicalCheckXI = Convert.ToBoolean(collecton["MechanicalCheckXI"].Split(',')[0]);
                    access.MechanicalRemarkThXI = Convert.ToString(collecton["MechanicalRemarksXI"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksXI"]));
                    access.MechanicalRemarkEnXI = Convert.ToString(collecton["MechanicalRemarksXI"] == null ? "อุปกรณ์ใช้งานได้ดี" : Convert.ToString(collecton["MechanicalRemarksXI"]));
                    access.MechanicalPointXI = Convert.ToInt32(collecton["MechanicalPointXI"]);

                    access.TitleMechanicalNameXII = "Heater/ หม้อต้ม";
                    access.MechanicalCheckXII = Convert.ToBoolean(collecton["MechanicalCheckXI"].Split(',')[0]);
                    access.MechanicalRemarkThXII = Convert.ToString(collecton["MechanicalRemarksXII"] == null ? "หม้อต้ม การใช้งาน ปกติ" : Convert.ToString(collecton["MechanicalRemarksXII"]));
                    access.MechanicalRemarkEnXII = Convert.ToString(collecton["MechanicalRemarksXII"] == null ? "หม้อต้ม การใช้งาน ปกติ" : Convert.ToString(collecton["MechanicalRemarksXII"]));
                    access.MechanicalPointXII = Convert.ToInt32(collecton["MechanicalPointXII"]);

                    access.CreateBy = (string)Session["User"];

                    bool result = accessRepo.UpdateMECHANICAL(access);

                    if (result)
                    {
                        return RedirectToAction("MWWDISPENSER");

                    }
                    return View();
                }
            }
            catch
            {
                return View();
            }
        }

        [HttpGet]
        public ActionResult MechanicalRemarkIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "อุปกรณ์");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "อุปกรณ์ใช้งานได้ดี");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksI = mechanicalRemarks,
                MechanicalRemarkISelect = selectlistI
            };
            return View(access);

        }
        [HttpGet]
        public ActionResult MechanicalRemarkIIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "อุปกรณ์");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "อุปกรณ์ใช้งานได้ดี");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksII = mechanicalRemarks,
                MechanicalRemarkIISelect = selectlistI
            };
            return View(access);

        }

        [HttpGet]
        public ActionResult MechanicalRemarkIIIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "แขนฉีด");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "อุปกรณ์ใช้งานได้ดี ไม่มีการอุดตันของแขนฉีด");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksIII = mechanicalRemarks,
                MechanicalRemarkIIISelect = selectlistI
            };
            return View(access);

        }

        [HttpGet]
        public ActionResult MechanicalRemarkIVProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "แขนฉีด");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "อุปกรณ์ใช้งานได้ดี ไม่มีการอุดตันของแขนฉีด");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksIV = mechanicalRemarks,
                MechanicalRemarkIVSelect = selectlistI
            };
            return View(access);

        }

        [HttpGet]
        public ActionResult MechanicalRemarkVProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "ตะแกรงตัก");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "มีการทำความสะอาด ตะแกรงตักเศษอาหาร ดี ไม่มีเศษอาหารสะสม");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksV = mechanicalRemarks,
                MechanicalRemarkVSelect = selectlistI
            };
            return View(access);

        }

        [HttpGet]
        public ActionResult MechanicalRemarkVIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "อุปกรณ์");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "อุปกรณ์ใช้งานได้ดี");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksVI = mechanicalRemarks,
                MechanicalRemarkVISelect = selectlistI
            };
            return View(access);

        }
        [HttpGet]
        public ActionResult MechanicalRemarkVIIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "อุปกรณ์");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "อุปกรณ์ใช้งานได้ดี");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksVII = mechanicalRemarks,
                MechanicalRemarkVIISelect = selectlistI
            };
            return View(access);

        }
        [HttpGet]
        public ActionResult MechanicalRemarkVIIIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "อุปกรณ์");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "อุปกรณ์ใช้งานได้ดี");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksVIII = mechanicalRemarks,
                MechanicalRemarkVIIISelect = selectlistI
            };
            return View(access);

        }
        [HttpGet]
        public ActionResult MechanicalRemarkIXProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "อุปกรณ์");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "อุปกรณ์ใช้งานได้ดี");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksIX = mechanicalRemarks,
                MechanicalRemarkIXSelect = selectlistI
            };
            return View(access);

        }
        [HttpGet]
        public ActionResult MechanicalRemarkXProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "ม่าน");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "ม่าน อยู่ในสภาพดี");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksX = mechanicalRemarks,
                MechanicalRemarkXSelect = selectlistI
            };
            return View(access);

        }
        [HttpGet]
        public ActionResult MechanicalRemarkXIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "อุปกรณ์");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "อุปกรณ์ใช้งานได้ดี");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksXI = mechanicalRemarks,
                MechanicalRemarkXISelect = selectlistI
            };
            return View(access);

        }
        [HttpGet]
        public ActionResult MechanicalRemarkXIIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            MechanicalRemarkRepo mechanicalRemarkRepo = new MechanicalRemarkRepo();
            IEnumerable<MechanicalRemarkModels> mechanicalRemarks = mechanicalRemarkRepo.GetMechanicalRemark().Where(r => r.TitleMechanicalType == "หม้อต้ม");

            if (isFitter)
            {

                mechanicalRemarks = mechanicalRemarks.Where(r => r.MechanicalRemarkTh != "หม้อต้ม การใช้งาน ปกติ");
            }

            string selectMechanicalRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in mechanicalRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.MechanicalRemarkTh == selectMechanicalRemark),
                                                          Text = r.MechanicalRemarkTh,
                                                          Value = r.MechanicalRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                MechanicalRemarksXII = mechanicalRemarks,
                MechanicalRemarkXIISelect = selectlistI
            };
            return View(access);

        }
        public ActionResult MWWDISPENSER()
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ConditonRemarkRepo conditionRemarkRepo = new ConditonRemarkRepo();
            IEnumerable<ConditonRemarkModels> conditionRemarks = conditionRemarkRepo.GetConditionRemark();

            string selectMWWDispenserRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in conditionRemarks.Where(r => r.TitleMwwDispenserId == 1)
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.ConditionRemarkTh == selectMWWDispenserRemark),
                                                          Text = r.ConditionRemarkTh,
                                                          Value = r.ConditionRemarkTh.ToString()
                                                      };



            var access = new AccessModels
            {

                ConditionRemarkI = conditionRemarks.Where(r => r.TitleMwwDispenserId == 1),
                ConditionRemarkISelect = selectlistI

            };


            return View(access);
        }

        [HttpPost]
        public ActionResult MWWDISPENSER(FormCollection collecton)
        {
            try
            {
                // TODO: Add update logic here
                {
                    if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                    // TODO: Add update logic here
                    AccessRepo accessRepo = new AccessRepo();
                    AccessModels access = new AccessModels();
                    access.ConditionMachineI = Convert.ToString(collecton["ConditionMachineI"]);
                    access.ConditionProbeCheckI = Convert.ToBoolean(collecton["ConditionProbeCheckI"].Split(',')[0]);
                    access.ConditionDettubeCheckI = Convert.ToBoolean(collecton["ConditionDettubeCheckI"].Split(',')[0]);
                    access.ConditionRinsetubeCheckI = Convert.ToBoolean(collecton["ConditionRinsetubeCheckI"].Split(',')[0]);
                    access.ConditionRemarkThI = Convert.ToString(collecton["ConditionRemarkI"] == null ? "ใช้งานได้ตามปกติ" : Convert.ToString(collecton["ConditionRemarkI"]));
                    access.ConditionRemarkEnI = Convert.ToString(collecton["ConditionRemarkI"] == null ? "ใช้งานได้ตามปกติ" : Convert.ToString(collecton["ConditionRemarkI"]));
                    access.ConditionRemarkPointI = Convert.ToInt32(collecton["ConditionRemarkPointI"]);

                    access.CreateBy = (string)Session["User"];

                    bool result = accessRepo.UpdateMWWDispenser(access);

                    if (result)
                    {
                        return RedirectToAction("FEEDER");
                    }
                    return View();
                }
            }

            catch
            {
                return View();
            }
        }


        [HttpGet]
        public ActionResult MWWDispenserRemarkIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            ConditonRemarkRepo conditionRemarkRepo = new ConditonRemarkRepo();
            IEnumerable<ConditonRemarkModels> conditionRemarks = conditionRemarkRepo.GetConditionRemark().Where(r => r.TitleMwwDispenserId == 1);
            if (isFitter)
            {
                conditionRemarks = conditionRemarks.Where(r => r.ConditionRemarkTh != "ใช้งานได้ตามปกติ");
            }

            string selectResultRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in conditionRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.ConditionRemarkTh == selectResultRemark),
                                                          Text = r.ConditionRemarkTh,
                                                          Value = r.ConditionRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                ConditionRemarkI = conditionRemarks,
                ConditionRemarkISelect = selectlistI
            };
            return View(access);

        }

        public ActionResult FEEDER()
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            FeederRemarkRepo feederRemarkRepo = new FeederRemarkRepo();
            IEnumerable<FeederRemarkModels> feederRemarks = feederRemarkRepo.GetFeederRemark();

            string selectFeederRemark = "";
            IEnumerable<SelectListItem> selectlistI = from r in feederRemarks.Where(r => r.TitleFeeDerId == 1)
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                          Text = r.FeederRemarkTh,
                                                          Value = r.FeederRemarkTh.ToString()
                                                      };
            IEnumerable<SelectListItem> selectlistII = from r in feederRemarks.Where(r => r.TitleFeeDerId == 1)
                                                       select new SelectListItem
                                                       {
                                                           Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                           Text = r.FeederRemarkTh,
                                                           Value = r.FeederRemarkTh.ToString()
                                                       };
            IEnumerable<SelectListItem> selectlistIII = from r in feederRemarks.Where(r => r.TitleFeeDerId == 2)
                                                        select new SelectListItem
                                                        {
                                                            Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                            Text = r.FeederRemarkTh,
                                                            Value = r.FeederRemarkTh.ToString()
                                                        };
            IEnumerable<SelectListItem> selectlistIV = from r in feederRemarks.Where(r => r.TitleFeeDerId == 2)
                                                       select new SelectListItem
                                                       {
                                                           Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                           Text = r.FeederRemarkTh,
                                                           Value = r.FeederRemarkTh.ToString()
                                                       };
            IEnumerable<SelectListItem> selectlistV = from r in feederRemarks.Where(r => r.TitleFeeDerId == 3)
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                          Text = r.FeederRemarkTh,
                                                          Value = r.FeederRemarkTh.ToString()
                                                      };

            IEnumerable<SelectListItem> selectlistVI = from r in feederRemarks.Where(r => r.TitleFeeDerId == 3)
                                                       select new SelectListItem
                                                       {
                                                           Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                           Text = r.FeederRemarkTh,
                                                           Value = r.FeederRemarkTh.ToString()
                                                       };
            IEnumerable<SelectListItem> selectlistVII = from r in feederRemarks.Where(r => r.TitleFeeDerId == 3)
                                                        select new SelectListItem
                                                        {
                                                            Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                            Text = r.FeederRemarkTh,
                                                            Value = r.FeederRemarkTh.ToString()
                                                        };
            IEnumerable<SelectListItem> selectlistVIII = from r in feederRemarks.Where(r => r.TitleFeeDerId == 3)
                                                         select new SelectListItem
                                                         {
                                                             Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                             Text = r.FeederRemarkTh,
                                                             Value = r.FeederRemarkTh.ToString()
                                                         };
            IEnumerable<SelectListItem> selectlistIX = from r in feederRemarks.Where(r => r.TitleFeeDerId == 4)
                                                       select new SelectListItem
                                                       {
                                                           Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                           Text = r.FeederRemarkTh,
                                                           Value = r.FeederRemarkTh.ToString()
                                                       };
            IEnumerable<SelectListItem> selectlistX = from r in feederRemarks.Where(r => r.TitleFeeDerId == 4)
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                          Text = r.FeederRemarkTh,
                                                          Value = r.FeederRemarkTh.ToString()
                                                      };

            IEnumerable<SelectListItem> selectlistXI = from r in feederRemarks.Where(r => r.TitleFeeDerId == 4)
                                                       select new SelectListItem
                                                       {
                                                           Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                           Text = r.FeederRemarkTh,
                                                           Value = r.FeederRemarkTh.ToString()
                                                       };
            IEnumerable<SelectListItem> selectlistXII = from r in feederRemarks.Where(r => r.TitleFeeDerId == 4)
                                                        select new SelectListItem
                                                        {
                                                            Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                            Text = r.FeederRemarkTh,
                                                            Value = r.FeederRemarkTh.ToString()
                                                        };
            IEnumerable<SelectListItem> selectlistXIII = from r in feederRemarks.Where(r => r.TitleFeeDerId == 4)
                                                         select new SelectListItem
                                                         {
                                                             Selected = (r.FeederRemarkTh == selectFeederRemark),
                                                             Text = r.FeederRemarkTh,
                                                             Value = r.FeederRemarkTh.ToString()
                                                         };

            var access = new AccessModels
            {
                FeederRemarksI = feederRemarks.Where(r => r.TitleFeeDerId == 1),
                FeederRemarkISelect = selectlistI
             ,
                FeederRemarksII = feederRemarks.Where(r => r.TitleFeeDerId == 1),
                FeederRemarkIISelect = selectlistII
             ,
                FeederRemarksIII = feederRemarks.Where(r => r.TitleFeeDerId == 2),
                FeederRemarkIIISelect = selectlistIII
             ,
                FeederRemarksIV = feederRemarks.Where(r => r.TitleFeeDerId == 2),
                FeederRemarkIVSelect = selectlistIV
             ,
                FeederRemarksV = feederRemarks.Where(r => r.TitleFeeDerId == 3),
                FeederRemarkVSelect = selectlistV
             ,
                FeederRemarksVI = feederRemarks.Where(r => r.TitleFeeDerId == 3),
                FeederRemarkVISelect = selectlistVI
              ,
                FeederRemarksVII = feederRemarks.Where(r => r.TitleFeeDerId == 3),
                FeederRemarkVIISelect = selectlistVII
              ,
                FeederRemarksVIII = feederRemarks.Where(r => r.TitleFeeDerId == 3),
                FeederRemarkVIIISelect = selectlistVIII
              ,
                FeederRemarksIX = feederRemarks.Where(r => r.TitleFeeDerId == 4),
                FeederRemarkIXSelect = selectlistIX
              ,
                FeederRemarksX = feederRemarks.Where(r => r.TitleFeeDerId == 4),
                FeederRemarkXSelect = selectlistX
              ,
                FeederRemarksXI = feederRemarks.Where(r => r.TitleFeeDerId == 4),
                FeederRemarkXISelect = selectlistXI
                ,
                FeederRemarksXII = feederRemarks.Where(r => r.TitleFeeDerId == 4),
                FeederRemarkXIISelect = selectlistXII
                 ,
                FeederRemarksXIII = feederRemarks.Where(r => r.TitleFeeDerId == 4),
                FeederRemarkXIIISelect = selectlistXIII
            };


            return View(access);
        }

        [HttpPost]
        public ActionResult FEEDER(FormCollection collecton)
        {
            try
            {
                {
                    if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                    // TODO: Add update logic here
                    AccessRepo accessRepo = new AccessRepo();
                    AccessModels access = new AccessModels();
                    access.TitleFeederI = "QFM High Flow";
                    access.FeederRemarkThI = Convert.ToString(collecton["FeederRemarksI"]);
                    access.FeederRemarkEngI = Convert.ToString(collecton["FeederRemarksI"]);
                    access.FeederStandardI = Convert.ToInt32(collecton["FeederStandardI"]);
                    access.FeederActualI = Convert.ToInt32(collecton["FeederActualI"]);
                    access.FeederPointI = Convert.ToInt32(collecton["FeederPointI"]);

                    access.TitleFeederII = "QFM High Flow";
                    access.FeederRemarkThII = Convert.ToString(collecton["FeederRemarksII"]);
                    access.FeederRemarkEngII = Convert.ToString(collecton["FeederRemarksII"]);
                    access.FeederStandardII = Convert.ToInt32(collecton["FeederStandardII"]);
                    access.FeederActualII = Convert.ToInt32(collecton["FeederActualII"]);
                    access.FeederPointII = Convert.ToInt32(collecton["FeederPointII"]);

                    access.TitleFeederIII = "QFM Low Flow";
                    access.FeederRemarkThIII = Convert.ToString(collecton["FeederRemarksIII"]);
                    access.FeederRemarkEngIII = Convert.ToString(collecton["FeederRemarksIII"]);
                    access.FeederStandardIII = Convert.ToInt32(collecton["FeederStandardIII"]);
                    access.FeederActualIII = Convert.ToInt32(collecton["FeederActualIII"]);
                    access.FeederPointIII = Convert.ToInt32(collecton["FeederPointIII"]);

                    access.TitleFeederIV = "QFM Low Flow";
                    access.FeederRemarkThIV = Convert.ToString(collecton["FeederRemarksIV"]);
                    access.FeederRemarkEngIV = Convert.ToString(collecton["FeederRemarksIV"]);
                    access.FeederStandardIV = Convert.ToInt32(collecton["FeederStandardIV"]);
                    access.FeederActualIV = Convert.ToInt32(collecton["FeederActualIV"]);
                    access.FeederPointIV = Convert.ToInt32(collecton["FeederPointIV"]);

                    access.TitleFeederV = "J-FILL";
                    access.FeederRemarkThV = Convert.ToString(collecton["FeederRemarksV"]);
                    access.FeederRemarkEngV = Convert.ToString(collecton["FeederRemarksV"]);
                    access.FeederStandardV = Convert.ToInt32(collecton["FeederStandardV"]);
                    access.FeederActualV = Convert.ToInt32(collecton["FeederActualV"]);
                    access.FeederPointV = Convert.ToInt32(collecton["FeederPointV"]);

                    access.TitleFeederVI = "J-FILL";
                    access.FeederRemarkThVI = Convert.ToString(collecton["FeederRemarksVI"]);
                    access.FeederRemarkEngVI = Convert.ToString(collecton["FeederRemarksVI"]);
                    access.FeederStandardVI = Convert.ToInt32(collecton["FeederStandardVI"]);
                    access.FeederActualVI = Convert.ToInt32(collecton["FeederActualVI"]);
                    access.FeederPointVI = Convert.ToInt32(collecton["FeederPointVI"]);

                    access.TitleFeederVII = "J-FILL";
                    access.FeederRemarkThVII = Convert.ToString(collecton["FeederRemarksVII"]);
                    access.FeederRemarkEngVII = Convert.ToString(collecton["FeederRemarksVII"]);
                    access.FeederStandardVII = Convert.ToInt32(collecton["FeederStandardVII"]);
                    access.FeederActualVII = Convert.ToInt32(collecton["FeederActualVII"]);
                    access.FeederPointVII = Convert.ToInt32(collecton["FeederPointVII"]);

                    access.TitleFeederVIII = "J-FILL";
                    access.FeederRemarkThVIII = Convert.ToString(collecton["FeederRemarksVIII"]);
                    access.FeederRemarkEngVIII = Convert.ToString(collecton["FeederRemarksVIII"]);
                    access.FeederStandardVIII = Convert.ToInt32(collecton["FeederStandardVIII"]);
                    access.FeederActualVIII = Convert.ToInt32(collecton["FeederActualVIII"]);
                    access.FeederPointVIII = Convert.ToInt32(collecton["FeederPointVIII"]);

                    access.TitleFeederIX = "Pelican Pump เพอริแกน ปั้ม";
                    access.FeederRemarkThIX = Convert.ToString(collecton["FeederRemarksIX"]);
                    access.FeederRemarkEngIX = Convert.ToString(collecton["FeederRemarksIX"]);
                    access.FeederStandardIX = Convert.ToInt32(collecton["FeederStandardIX"]);
                    access.FeederActualIX = Convert.ToInt32(collecton["FeederActualIX"]);
                    access.FeederPointIX = Convert.ToInt32(collecton["FeederPointIX"]);

                    access.TitleFeederX = "Pelican Pump เพอริแกน ปั้ม";
                    access.FeederRemarkThX = Convert.ToString(collecton["FeederRemarksX"]);
                    access.FeederRemarkEngX = Convert.ToString(collecton["FeederRemarksX"]);
                    access.FeederStandardX = Convert.ToInt32(collecton["FeederStandardX"]);
                    access.FeederActualX = Convert.ToInt32(collecton["FeederActualX"]);
                    access.FeederPointX = Convert.ToInt32(collecton["FeederPointX"]);

                    access.TitleFeederXI = "Pelican Pump เพอริแกน ปั้ม";
                    access.FeederRemarkThXI = Convert.ToString(collecton["FeederRemarksXI"]);
                    access.FeederRemarkEngXI = Convert.ToString(collecton["FeederRemarksXI"]);
                    access.FeederStandardXI = Convert.ToInt32(collecton["FeederStandardXI"]);
                    access.FeederActualXI = Convert.ToInt32(collecton["FeederActualXI"]);
                    access.FeederPointXI = Convert.ToInt32(collecton["FeederPointXI"]);

                    access.TitleFeederXII = "Pelican Pump เพอริแกน ปั้ม";
                    access.FeederRemarkThXII = Convert.ToString(collecton["FeederRemarksXII"]);
                    access.FeederRemarkEngXII = Convert.ToString(collecton["FeederRemarksXII"]);
                    access.FeederStandardXII = Convert.ToInt32(collecton["FeederStandardXII"]);
                    access.FeederActualXII = Convert.ToInt32(collecton["FeederActualXII"]);
                    access.FeederPointXII = Convert.ToInt32(collecton["FeederPointXII"]);

                    access.TitleFeederXIII = "Pelican Pump เพอริแกน ปั้ม";
                    access.FeederRemarkThXIII = Convert.ToString(collecton["FeederRemarksXIII"]);
                    access.FeederRemarkEngXIII = Convert.ToString(collecton["FeederRemarksXIII"]);
                    access.FeederStandardXIII = Convert.ToInt32(collecton["FeederStandardXIII"]);
                    access.FeederActualXIII = Convert.ToInt32(collecton["FeederActualXIII"]);
                    access.FeederPointXIII = Convert.ToInt32(collecton["FeederPointXIII"]);

                    access.CreateBy = (string)Session["User"];

                    bool result = accessRepo.UpdateFeeder(access);

                    if (result)
                    {
                        return RedirectToAction("ONSITETRAINING");
                    }
                    return View();
                }

            }
            catch
            {
                return View();
            }
        }

        public ActionResult ONSITETRAINING()
        {
            //TrainingRemarkRepo trainingRemarkRepo = new TrainingRemarkRepo();
            //IEnumerable<TrainingRemarkModels> TrainingRemarks = trainingRemarkRepo.GetTrainingRemark();

            //string selectTrainingRemark = "";
            //IEnumerable<SelectListItem> selectlistI = from r in TrainingRemarks.Where(r => r.TitleOnsiteTraningId == 1)
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.TrainingRemarkTh == selectTrainingRemark),
            //                                              Text = r.TrainingRemarkTh,
            //                                              Value = r.TrainingRemarkTh.ToString()
            //                                          };
            //IEnumerable<SelectListItem> selectlistII = from r in TrainingRemarks.Where(r => r.TitleOnsiteTraningId == 2)
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.TrainingRemarkTh == selectTrainingRemark),
            //                                               Text = r.TrainingRemarkTh,
            //                                               Value = r.TrainingRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistIII = from r in TrainingRemarks.Where(r => r.TitleOnsiteTraningId == 3)
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.TrainingRemarkTh == selectTrainingRemark),
            //                                                Text = r.TrainingRemarkTh,
            //                                                Value = r.TrainingRemarkTh.ToString()
            //                                            };
            //IEnumerable<SelectListItem> selectlistIV = from r in TrainingRemarks.Where(r => r.TitleOnsiteTraningId == 4)
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.TrainingRemarkTh == selectTrainingRemark),
            //                                               Text = r.TrainingRemarkTh,
            //                                               Value = r.TrainingRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistV = from r in TrainingRemarks.Where(r => r.TitleOnsiteTraningId == 5)
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.TrainingRemarkTh == selectTrainingRemark),
            //                                              Text = r.TrainingRemarkTh,
            //                                              Value = r.TrainingRemarkTh.ToString()
            //                                          };

            //IEnumerable<SelectListItem> selectlistVI = from r in TrainingRemarks.Where(r => r.TitleOnsiteTraningId == 6)
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.TrainingRemarkTh == selectTrainingRemark),
            //                                               Text = r.TrainingRemarkTh,
            //                                               Value = r.TrainingRemarkTh.ToString()
            //                                           };
            //IEnumerable<SelectListItem> selectlistVII = from r in TrainingRemarks.Where(r => r.TitleOnsiteTraningId == 7)
            //                                            select new SelectListItem
            //                                            {
            //                                                Selected = (r.TrainingRemarkTh == selectTrainingRemark),
            //                                                Text = r.TrainingRemarkTh,
            //                                                Value = r.TrainingRemarkTh.ToString()
            //                                            };
            //IEnumerable<SelectListItem> selectlistVIII = from r in TrainingRemarks.Where(r => r.TitleOnsiteTraningId == 8)
            //                                             select new SelectListItem
            //                                             {
            //                                                 Selected = (r.TrainingRemarkTh == selectTrainingRemark),
            //                                                 Text = r.TrainingRemarkTh,
            //                                                 Value = r.TrainingRemarkTh.ToString()
            //                                             };
            //IEnumerable<SelectListItem> selectlistIX = from r in TrainingRemarks.Where(r => r.TitleOnsiteTraningId == 9)
            //                                           select new SelectListItem
            //                                           {
            //                                               Selected = (r.TrainingRemarkTh == selectTrainingRemark),
            //                                               Text = r.TrainingRemarkTh,
            //                                               Value = r.TrainingRemarkTh.ToString()
            //                                           };


            var access = new AccessModels
            {
                TreningICheck = true,
                TreningIICheck = true,
                TreningIIICheck = true,
                TreningIVCheck = true,
                TreningVCheck = true,
                TreningVICheck = true,
                TreningVIICheck = true,
                TreningVIIICheck = true

            };


            return View(access);
        }

        [HttpPost]
        public ActionResult ONSITETRAINING(FormCollection collecton)
        {
            try
            {
                if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                // TODO: Add update logic here
                AccessRepo accessRepo = new AccessRepo();
                AccessModels access = new AccessModels();
                access.TitleTraningI = "MACHINE WARE WASHING เครื่องล้างจานอัติโนมัติ";
                access.TreningICheck = Convert.ToBoolean(collecton["TreningICheck"].Split(',')[0]);
                access.TitleTraningII = "FLOOR CLEANING การทำความสะอาดพื้น";
                access.TreningIICheck = Convert.ToBoolean(collecton["TreningIICheck"].Split(',')[0]);
                access.TitleTraningIII = "WINDOW CLEANING การทำความสะอาดหน้าต่าง กระจก";
                access.TreningIIICheck = Convert.ToBoolean(collecton["TreningIIICheck"].Split(',')[0]);
                access.TitleTraningIV = "HAND WASHING การล้างมือ";
                access.TreningIVCheck = Convert.ToBoolean(collecton["TreningIVCheck"].Split(',')[0]);
                access.TitleTraningV = "3 SINK COMPARTMENT การล้างจานแบบ 3 ซิงค์";
                access.TreningVCheck = Convert.ToBoolean(collecton["TreningVCheck"].Split(',')[0]);
                access.TitleTraningVI = "BASIC EQUIPMENT CLEANING การใช้อุปกรณ์ทำความสะอาดเบื้องต้น";
                access.TreningVICheck = Convert.ToBoolean(collecton["TreningVICheck"].Split(',')[0]);
                access.TitleTraningVII = "DISPENSING EQUIPMENT การใช้เครื่องจ่ายน้ำยา";
                access.TreningVIICheck = Convert.ToBoolean(collecton["TreningVIICheck"].Split(',')[0]);
                access.TitleTraningVIII = "FOOD SAFETY ความปลอดภัยด้านอาหาร";
                access.TreningVIIICheck = Convert.ToBoolean(collecton["TreningVIIICheck"].Split(',')[0]);

                access.CreateBy = (string)Session["User"];

                bool result = accessRepo.UpdateTraining(access);

                if (result)
                {
                    return RedirectToAction("HandSoapDispenser");
                }
                return View();

            }
            catch
            {
                return View();
            }
        }

        public ActionResult HandSoapDispenser()
        {
            //HandSoapDispenserRemarkRepo handSoapDispenserRemarkRepo = new HandSoapDispenserRemarkRepo();
            //IEnumerable<HandSoapDispenserRemarkModels> HandSoapDispenserRemarks = handSoapDispenserRemarkRepo.GetHandSoapDispenserRemark();

            //string selectHandSoapDispenserRemark = "";
            //IEnumerable<SelectListItem> selectlistI = from r in HandSoapDispenserRemarks.Where(r => r.TitleHandSoapDispenserId == 1)
            //                                          select new SelectListItem
            //                                          {
            //                                              Selected = (r.HandSoapDispenserRemarkTh == selectHandSoapDispenserRemark),
            //                                              Text = r.HandSoapDispenserRemarkTh,
            //                                              Value = r.HandSoapDispenserRemarkTh.ToString()
            //                                          };
            //var access = new AccessModels
            //{
            //    HandSoapDispenserRemarkI = HandSoapDispenserRemarks.Where(r => r.TitleHandSoapDispenserId == 1),
            //    HandSoapDispenserRemarkISelect = selectlistI
            //};
            var access = new AccessModels
            {
                HandSoapDispenserCheck = true
            };

            return View(access);
        }

        [HttpPost]
        public ActionResult HandSoapDispenser(FormCollection collecton)
        {
            try
            {
                if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                // TODO: Add update logic here
                AccessRepo accessRepo = new AccessRepo();
                AccessModels access = new AccessModels();
                access.TitleHandSoapDispenser = "Hand Soap Dispenser กล่องสบู่ทุกจุด ทำงานปกติ";
                access.HandSoapDispenserCheck = Convert.ToBoolean(collecton["HandSoapDispenserCheck"].Split(',')[0]);
                access.HandSoapDispenserThRemarksI = Convert.ToString(collecton["HandSoapDispenserRemarkI"] == null ? "สามารถใช้งานได้ตามปกติ" : Convert.ToString(collecton["HandSoapDispenserRemarkI"]));
                access.HandSoapDispenserEngRemarksI = Convert.ToString(collecton["HandSoapDispenserRemarkI"] == null ? "สามารถใช้งานได้ตามปกติ" : Convert.ToString(collecton["HandSoapDispenserRemarkI"]));
                access.HandSoapDispenserRemarkPointI = Convert.ToInt32(collecton["HandSoapDispenserRemarkPointI"]);

                access.CreateBy = (string)Session["User"];

                bool result = accessRepo.UpdateHandSoapDispenser(access);

                if (result)
                {
                    return RedirectToAction("Comment");
                }
                return View();


            }
            catch
            {
                return View();
            }
        }


        [HttpGet]
        public ActionResult HandSoapDispenserRemarkIProcess(bool isFitter)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            HandSoapDispenserRemarkRepo handSoapDispenserRemarkRepo = new HandSoapDispenserRemarkRepo();
            IEnumerable<HandSoapDispenserRemarkModels> HandSoapDispenserRemarks = handSoapDispenserRemarkRepo.GetHandSoapDispenserRemark().Where(r => r.TitleHandSoapDispenserId == 1); ;

            if (isFitter)
            {
                HandSoapDispenserRemarks = HandSoapDispenserRemarks.Where(r => r.HandSoapDispenserRemarkTh != "สามารถไช้งานได้ตามปกติ");
            }

            string selectProcedureRemark = "";
            IEnumerable<SelectListItem> selectlistV = from r in HandSoapDispenserRemarks
                                                      select new SelectListItem
                                                      {
                                                          Selected = (r.HandSoapDispenserRemarkTh == selectProcedureRemark),
                                                          Text = r.HandSoapDispenserRemarkTh,
                                                          Value = r.HandSoapDispenserRemarkTh.ToString()
                                                      };

            var access = new AccessModels
            {
                HandSoapDispenserRemarksI = HandSoapDispenserRemarks,
                HandSoapDispenserRemarkISelect = selectlistV
            };
            return View(access);

        }

        public ActionResult Comment()
        {
            AccessModels access = new AccessModels();
            return View();
        }

        [HttpPost]
        public ActionResult Comment(FormCollection collecton)
        {
            try
            {
                if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }

                AccessModels access = new AccessModels();
                AccessRepo accessRepo = new AccessRepo();
                access.VisitComment = Convert.ToString(collecton["VisitComment"]);

                access.CreateBy = (string)Session["User"];
                bool result = accessRepo.Finish(access);

                if (result)
                {
                    return RedirectToAction("Index");

                }
                return View();
            }
            catch
            {
                return View();
            }
        }

        public ActionResult Approve()
        {
            AccessModels access = new AccessModels();

            return View(access);
        }

        [HttpPost]
        public ActionResult Approve(FormCollection collection)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            // TODO: Add update logic here
            AccessModels access = new AccessModels();
            access.SignBy = collection["SignBy"];
            access.Status = "Active";
            access.CreateBy = (string)Session["User"];
            if (access.SignBy != "")
            {
                access.Status = "Approve";
            }
            AccessRepo accessRepo = new AccessRepo();
            bool result = accessRepo.Approve(access);


            if (result)
            {
                return RedirectToAction("Index");

            }
            return RedirectToAction("Approve");

        }


        //
        // GET: /VisitProcess/Edit/5

        public ActionResult ApproveForList(string id)
        {
            AccessModels access = new AccessModels();
            access.FSR_NO = id;
            return View(access);
        }

        //
        // POST: /VisitProcess/Edit/5

        [HttpPost]
        public ActionResult ApproveForList(string id, FormCollection collection)
        {
            try
            {
                if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
                AccessRepo accessRepo = new AccessRepo();
                AccessModels access = new AccessModels();

                AdminCustomerRepo adminCustomerRepo = new AdminCustomerRepo();
                access.SignBy = adminCustomerRepo.GetAdminCustomer(id).Where(a => a.CodeConfirm == collection["SignBy"]).Select(a => a.AdminId).FirstOrDefault();
                if (access.SignBy == null)
                {
                    TempData["errormessage"] = "Code Confirm  Not Found.";
                    return RedirectToAction("ApproveForList");
                }
                access.FSR_NO = id;
                access.UpdateBy = (string)Session["User"];
                bool result = accessRepo.Approve(access);
                if (result)
                {
                    return RedirectToAction("Index");
                }

                return RedirectToAction("ApproveForList");
            }
            catch (Exception ex)
            {
                return View();
            }
        }

        //
        // GET: /VisitProcess/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /VisitProcess/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
